# Modified Azimuthal Equidistant

In order to understand how to compute the formulas below, keep in mind that wxMaxima uses results of variable assignments ("variable: value" or "define(functionName, algebraicExpression)") in later calculations.

In this document, the formulas should be computed without substitution by variable assignments. For example, the ψ(φ) expression in EPSG guidance notes is defined as a function of ν(φ) expression. But in this document, we need to evaluate ψ(φ) before ν(φ) for keeping the expressions simple. This can be accomplished by computing "define(ψ(φ), expression)" first then computing "define(ν(φ), expression)". 

The intent is to simplify the expression of functions (especially those of derivatives).

Computation order: 
From the last to the first formulas defined in section "1 Definition from EPSG guidance notes":
    -> Compute the definition of a function;
    -> Compute the partial derivatives of the function

If you want the exact definition of these functions (without substitution), compute this document in normal order.

## Definition from EPSG guidance notes

### Simplification

We consider λ_0 equal to zero (to be computed first). 

λ_0: 0$

### Definitions of the functions that compose the projection

### ν

define(ν(φ), 1 / sqrt(1 - e^2 * sin(φ)^2));

### ψ

define(ψ(φ), atan((1 - e^2) * tan(φ) + e^2 * ν_0 * sin(φ_0) / (ν(φ) * cos(φ))));

### α

define(α(φ, λ), atan2(sin (λ - λ_0), cos(φ_0) * tan(ψ(φ)) - sin(φ_0) * cos (λ - λ_0)));

### H

define(H(φ, λ), e * cos(φ_0) * cos(α(φ, λ)) / sqrt(1 - e^2) );

### Definition of s when sin(α) = 0

This expression is intentionally not multiplied by the SIGN(cos(α)) (as describe in EPSG guidance notes) to compute the derivative because it does not seem to be supported by wxMaxima.

define(s(φ, λ), asin(cos(φ_0) * sin(ψ(φ)) - sin(φ_0) * cos(ψ(φ))));

### Definition of s when sin(α) ≠ 0

define(s(φ, λ), asin(sin(λ - λ_0) * cos(ψ(φ)) / sin(α(φ, λ))));

### h1, h2, h3, h4

These functions are used to decompose the expression of c.

define(h1(φ, λ), H(φ, λ)^2 * (1 - H(φ, λ)^2));
define(h2(φ, λ), G * H(φ, λ) * (1 - 2 * H(φ, λ)^2));
define(h3(φ, λ), H(φ, λ)^2 * (4 - 7 * H(φ, λ)^2) - 3 * G^2 * (1 - 7 * H(φ, λ)^2));
define(h4(φ, λ), G * H(φ, λ));

### c

define(c(φ, λ), ν_0 * s(φ, λ) * (
        1
        - (s(φ, λ)^2 / 6) * h1(φ, λ)
        + (s(φ, λ)^3 / 8) * h2(φ, λ)
        + (s(φ, λ)^4 / 120) * h3(φ, λ)
        - (s(φ, λ)^5 / 48) * h4(φ, λ)
    ));

### E

E for Easting equivalent to the coordinate x in the result of the projection.

define(E(φ, λ), FE + c(φ, λ) * sin(α(φ, λ)));

### N

N for Northing equivalent to the coordinate y in the result of the projection.

define(N(φ, λ), FN + c(φ, λ) . cos(α(φ, λ)));

## Derivative

### The partial derivative with respect to the variable λ

### ∂ν/∂λ

define(dν_φ(φ), diff(ν(φ), λ));

### ∂ψ/∂λ

define(dψ_φ(φ), diff(ψ(φ), λ));

### ∂α/∂λ

define(dα_λ(φ, λ), diff(α(φ, λ), λ));

### ∂H/∂λ

define(dH_λ(φ, λ), diff(H(φ, λ), λ));

### ∂s/∂λ when sin(α) = 0

For implementation this expression must be multiplied by SIGN(cos(α)) because that term appears in the s expression given by EPSG guidance notes.
The function SIGN is acting like a constant everywhere on the subset of the (]-∞; 0[,  0,  ]0; +∞[) domain, so his derivative is equal to zero excepted at x = 0 where the derivative is undefined (point of discontinuity).

define(ds_λ(φ, λ), diff(s(φ, λ), λ));

### ∂s/∂λ when sin(α) ≠ 0

define(ds_λ(φ, λ), diff(s(φ, λ), λ));

### ∂h1/∂λ, ∂h2/∂λ, ∂h3/∂λ, ∂h4/∂λ

define(dh1_λ(φ, λ), diff(h1(φ, λ), λ));
define(dh2_λ(φ, λ), diff(h2(φ, λ), λ));
define(dh3_λ(φ, λ), diff(h3(φ, λ), λ));
define(dh4_λ(φ, λ), diff(h4(φ, λ), λ));

### ∂c/∂λ

define(dc_λ(φ, λ), diff(c(φ, λ), λ));

### ∂E/∂λ

define(dE_λ(φ, λ), diff(E(φ, λ), λ));

### ∂N/∂λ

define(dN_λ(φ, λ), diff(N(φ, λ), λ));

### The partial derivative with respect to the variable λ

### ∂ν/∂φ

define(dν_φ(φ), diff(ν(φ), φ));

### ∂ψ/∂φ

define(dψ_φ(φ), diff(ψ(φ), φ));

### ∂α/∂φ

define(dα_φ(φ, λ), diff(α(φ, λ), φ));

### ∂H/∂φ

define(dH_φ(φ, λ), diff(H(φ, λ), φ));

### ∂s/∂φ when sin(α) = 0

For implementation this expression must be multiplied by SIGN(cos(α)) because that term appears in the s expression given by EPSG guidance notes.
The function SIGN is acting like a constant everywhere on the subset of the (]-∞; 0[,  0,  ]0; +∞[) domain, so his derivative is equal to zero excepted at x = 0 where the derivative is undefined (point of discontinuity).

define(ds_φ(φ, λ), diff(s(φ, λ), φ));

### ∂s/∂φ when sin(α) ≠ 0

define(ds_φ(φ, λ), diff(s(φ, λ), φ));

### ∂h1/∂φ, ∂h2/∂φ, ∂h3/∂φ, ∂h4/∂φ

define(dh1_φ(φ, λ), diff(h1(φ, λ), φ));
define(dh2_φ(φ, λ), diff(h2(φ, λ), φ));
define(dh3_φ(φ, λ), diff(h3(φ, λ), φ));
define(dh4_φ(φ, λ), diff(h4(φ, λ), φ));

### ∂c/∂φ

define(dc_φ(φ, λ), diff(c(φ, λ), φ));

### ∂E/∂φ

define(dE_φ(φ, λ), diff(E(φ, λ), φ));

### ∂N/∂φ

define(dN_φ(φ, λ), diff(N(φ, λ), φ));